package com.gui.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * RegisterInterceptor
 * @author guigu
 * @QQ 1170258867
 * @date 2020/5/30
 * @description
 */
@Component
public class RegisterInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (request.getSession().getAttribute("user")==null){
            try {
                response.sendRedirect("https://gitee.com/oauth/authorize?client_id=c00be61bf0a58d91f6bfc3c5d34dd878148f120c93f1ea07c8bf0aac706debce&redirect_uri=http://localhost:8889/callback&response_type=code");
            } catch (IOException e) {
                e.printStackTrace();
            }
            return false;
        }
        return true;
    }
}
